using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.ContactsDomain;
using ShivamEMR.Model.DataInterfaces.ContactsDataInterf;
using ShivamEMR.Model;
//using ShivamEMR.Web.Areas.Contacts.Models;

namespace ShivamEMR.Web.Areas.Contacts.Controllers
{   
    public class ContactTypeController : Controller
    {
		private readonly IContactTypeRepository contacttypeRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public ContactTypeController() 
        {
            contacttypeRepository = Registry.RepositoryFactory.GetContactTypeRepository();
        }

        public ContactTypeController(IContactTypeRepository contacttypeRepository)
        {
			this.contacttypeRepository = contacttypeRepository;
        }

        //
        // GET: /ContactType/

        public ViewResult Index()
        {
           // return View(contacttypeRepository.AllIncluding(contacttype => contacttype.Contacts));
            return View(contacttypeRepository.All);
        }

        //
        // GET: /ContactType/Details/5

        public ViewResult Details(int id)
        {
            return View(contacttypeRepository.Find(id));
        }

        //
        // GET: /ContactType/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /ContactType/Create

        [HttpPost]
        public ActionResult Create(ContactType contacttype)
        {
            if (ModelState.IsValid) {
                contacttypeRepository.InsertOrUpdate(contacttype);
                contacttypeRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /ContactType/Edit/5
 
        public ActionResult Edit(int id)
        {
             return View(contacttypeRepository.Find(id));
        }

        //
        // POST: /ContactType/Edit/5

        [HttpPost]
        public ActionResult Edit(ContactType contacttype)
        {
            if (ModelState.IsValid) {
                contacttypeRepository.InsertOrUpdate(contacttype);
                contacttypeRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /ContactType/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(contacttypeRepository.Find(id));
        }

        //
        // POST: /ContactType/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var ctype = contacttypeRepository.Find(id);
            contacttypeRepository.Delete(ctype);
            contacttypeRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

